from application.config import appSettings
from werkzeug.security import generate_password_hash, check_password_hash
from masoniteorm.relationships import belongs_to

from ..base import BaseModel


class BrandUser(BaseModel):
    __table__ = appSettings.db_prefix + 'brand_users'

    __hidden__ = ['password_hash']

    # # 设置加密的方法,传入密码,对类属性进行操作
    # def set_password_hash_attribute(self, value):
    #     return generate_password_hash(value, method='pbkdf2')

    # 设置加密的方法,传入密码,对类属性进行操作
    def set_password(self, value):
        self.password_hash = generate_password_hash(value, method='pbkdf2:sha256')

    @staticmethod
    def get_password_hash(password):
        return generate_password_hash(password, method='pbkdf2:sha256')

    # 设置验证密码的方法
    def check_password(self, user_pwd):
        return check_password_hash(self.password_hash, user_pwd)

    @belongs_to('brand_id', 'brand_id')
    def brand(self):
        from .Company import Company
        return Company


__all__ = ['BrandUser']
